import { constantRoutes } from '@/router'
import store from '@/store'


/**
 * 判断用户是否拥有操作权限
 * 根据传入的权限标识，查看是否存在用户权限标识集合
 * @param perms
 */
// export function hasPermission(perms) {
//   let hasPermission = false
//   let permissions = store.state.user.perms;
//   if (permissions){
//     for (let i = 0, len = permissions.length; i < len; i++) {
//       if (permissions[i] === perms) {
//         hasPermission = true;
//         break
//       }
//     }
//   }
//   return hasPermission
// }


const state = {
  routes: []
}

const mutations = {
  SET_ROUTES: (state, routes) => {
    state.routes = constantRoutes.concat(routes)
  }
}

const actions = {
  generateRoutes({ commit }, routers) {
    return new Promise(resolve => {
      commit('SET_ROUTES', routers)
      resolve(routers)
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
